<?php
class UserSettings extends MainObject {

	protected $_language = null;

	protected $_leksPerPage = null;

	protected $_preferedDict = null;

	public function __construct($userId = null) {
		$this->_model = new UserSettingsObjModel();
		if($userId) {
			$settingsData = $this->_model->getUserSettings($userId);
			if(empty($settingsData)) {
				return;
			}
			foreach ($settingsData as $data) {
				$this->_id = $data->id_user;
				$this->_language = $data->language;
				$this->_leksPerPage = $data->leks_per_page;
				$this->_preferedDict = $data->prefer_dictionary;
			}
		}
	}

	public function getLanguage() {
		return $this->_language;
	}

	public function setLanguage($language) {
		$this->_language = $language;
	}

	public function getLeksPerPage() {
		return $this->_leksPerPage;
	}

	public function setLeksPerPage($leksPerPage) {
		$this->_leksPerPage = intval($leksPerPage);
	}

	public function getPreferDict() {
		return $this->_preferedDict;
	}

	public function setPreferDict($dictId) {
		$this->_preferedDict = intval($dictId);
	}

	protected function _update() {
		$this->_model->update($this);
	}

	protected function _save() {
		$this->_model->insert($this);
	}
}